﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Content.Master" Inherits="System.Web.Mvc.ViewPage<MethodWorx.CMS.UI.Models.CreateContentTemplateModel>" %>


<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">

<script language="javascript">
    $(document).ready(function () {


        $("#childChoiceCreate").click(function () {
            enableDisableChildContentTemplateForm();
        });

        $("#childChoiceAdd").click(function () {
            enableDisableChildContentTemplateForm();
        });

        $("#cancel").click(function () {
            window.location.href = "/Schema/Index";
        });

        $("#existingContentTemplate").change(setExistingContentTemplateLabel);

        $("#next").click(function () {
            var canContinue;
            canContinue = validateStep1();
            if (canContinue) {
                $("#step1").hide();
                $("#step2").show();
                $("#next").hide();
                $("#back").show();
                $("#finish").show();
            }
        });

        $("#back").click(function () {
            $("#step1").show();
            $("#step2").hide();
            $("#next").show();
            $("#back").hide();
            $("#finish").hide();
        });

        enableDisableChildContentTemplateForm();

        //
        //  if we are checked to begin with we can start on step 2
        if ($("input[@name='childChoice']:checked").val() != null) {
            //  show step 2
            $("#step1").hide();
            $("#step2").show();
            $("#next").hide();
            $("#back").show();
            $("#finish").show();
        }
        else {
            //  show step 1
            $("#step1").show();
            $("#step2").hide();
            $("#next").show();
            $("#back").hide();
            $("#finish").hide();
        }

    });

    function validateStep1() {
        $("#existingContentTemplateError").hide();
        if ($("input[@name='childChoice']:checked").val() == "create")
            return true;
        else if ($("input[@name='childChoice']:checked").val() == "add") {
            if ($("#existingContentTemplate").val() == "") {
                $("#existingContentTemplateError").show();
                return false;
            }
            else
                return true;
        }
    }

    function setupFormAction() {
        if ($("input[@name='childChoice']:checked").val() == "create") {
            $("#createTemplateForm").show();
            $("#addTemplateForm").hide();
            $("#inputForm").attr("action", "/ContentTemplate/Create");
        }
        else {
            $("#createTemplateForm").hide();
            $("#addTemplateForm").show();
            $("#inputForm").attr("action", "/ContentTemplate/Add");
        }

        setExistingContentTemplateLabel();
    }


    function enableDisableChildContentTemplateForm() {
        if ($("input[@name='childChoice']:checked").val() == "create") {
            $("#childContentTemplateForm").css("color", "silver");
            $("#existingContentTemplate").attr("disabled", true);
        }
        else if ($("input[@name='childChoice']:checked").val() == "add") {
            $("#childContentTemplateForm").css("color", "black");
            $("#existingContentTemplate").attr("disabled", false);
        }

        setupFormAction();
    }

    function setExistingContentTemplateLabel() {
        $("#contentTemplateName").text($("#existingContentTemplate option:selected").text());
    }

        </script>

        <form id="inputForm" method="post" action="<%=Url.Content("~/ContentTemplate/Create")%>">
            <%=Html.Hidden("id") %>

            <div class="formItem">
                <label>Page Template:</label> <%=this.Model.PageTemplate.Name %>
            </div>
            <div id="step1" style="display:none">
                <div>
	                <p>
    		            <label>Create New Content Template:</label>
                        <%=Html.RadioButton("childChoice", "create", new { id="childChoiceCreate"}) %>
                        <br />
		                <label>Add Existing Content Template:</label>
                        <%=Html.RadioButton("childChoice", "add", new { id="childChoiceAdd"}) %>
	                </p>
                </div>
                <div class="lp-block" style="margin-left:20px;color:Silver;" id="childContentTemplateForm">
	                <p>
		                <strong>Content Template:</strong><br />
                        <%=Html.DropDownList("existingContentTemplate", this.Model.GetExistingContentTemplatesSelectList(), "Please Select...", new { disabled = "disabled" })%>
                        <br />
                        <span id="existingContentTemplateError" class="field-validation-error" style="display:none">Please select a content template</span>
	                </p>
                </div>
            </div>
            <div id="step2" style="display:none">
                <div class="form">
                        <div id="createTemplateForm">
                            <div class="formItem">
		                        <label>Template Name:</label>
                                <%=Html.TextBox("ContentTemplateDetails.Name") %><br />
                                <%=Html.ValidationMessage("ContentTemplateDetails.Name") %>
                                <%=Html.ValidationMessage("Name") %>
                            </div>
                            <div class="formItem">
		                        <label>Template Description:</label>
                                <%=Html.TextArea("ContentTemplateDetails.Description", new { rows = 5 })%><br />
                                <%=Html.ValidationMessage("ContentTemplateDetails.Description")%>
                            </div>
                        </div>
                        <div id="addTemplateForm">
                            <div class="formItem">
                                <label>Content Template: </label>
                                <strong id="contentTemplateName"></strong>
                            </div>
                        </div>
                        <div class="formItem">
		                    <label>Minimum Required:</label>
                            <%=Html.TextBox("ConstraintDetails.MinimumRequired", null, new { @class="small" })%><br />
                            <%=Html.ValidationMessage("ConstraintDetails.MinimumRequired")%>
                        </div>
                        <div class="formItem">
		                    <label>Maximum Allowed:</label>
                            <%=Html.TextBox("ConstraintDetails.MaximumAllowed", null, new { @class="small" })%><br />
                            <%=Html.ValidationMessage("ConstraintDetails.MaximumAllowed")%>
                        </div>
                        <div class="formItem">
		                    <label>Name Constraint:</label>
                            <%=Html.TextBox("ConstraintDetails.NameConstraint")%><br />
                            <%=Html.ValidationMessage("ConstraintDetails.NameConstraint")%>
                        </div>
                </div>
            </div>
            <button id="next" type="button" style="display:none">Next >></button>
            <button id="back" type="button" style="display:none">Back <<</button>
            <button id="finish" type="submit" name="submit" value="finish" style="display:none">Finish</button>
            <button id="cancel" type="button">Cancel</button>
        </form>

</asp:Content>
